#ifndef _SPECTRUMDLG_H
#define _SPECTRUMDLG_H

//#include <string>
#include "lib/colorbutton.h"
class CSpectrumDlg : public CDialogImpl<CSpectrumDlg>, 
                 public CWinDataExchange<CSpectrumDlg>
{
	
public:
    enum { IDD = IDD_SPECTRUM };
 
    BEGIN_MSG_MAP(CSpectrumDlg)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
		MESSAGE_HANDLER(WM_SHOWWINDOW, OnShow)
		COMMAND_ID_HANDLER(IDOK, OnOK)
        COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
		COMMAND_HANDLER(IDC_RADIO2, BN_CLICKED, OnBnClickedRadio2)
		COMMAND_HANDLER(IDC_SPE_RADIO1, BN_CLICKED, OnBnClickedRadio2)

		REFLECT_NOTIFICATIONS ()
	END_MSG_MAP()
 
    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        CenterWindow();

		//DWORD c = RGB(0,0,160);
		cb_bgcolor.SubclassWindow(GetDlgItem(IDC_SPE_COLOR));
		//r_amp=0;
		r_amp = Config::SPE_Amplitude;
		r_unit = Config::SPE_Unit;
		r_ffs = Config::SPE_Scale;
		r_fd = Config::SPE_FREDisplay;
		b_islog = Config::SPE_IsLog;

		cb_bgcolor.SetColor( (COLORREF)Config::SPE_BGColor );
		cb_bgcolor.SetDefaultColor(Config::SPE_BGColor.def_get());
		UpdateUI();
		DoDataExchange(FALSE);
        return TRUE;    // let the system set the focus

    }

	LRESULT OnShow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
		return 0;
	}


    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        EndDialog(IDCANCEL);
        return 0;
    }

	LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        EndDialog(wID);
        return 0;
    }
	LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
		DoDataExchange(TRUE);
		Config::SPE_BGColor = cb_bgcolor.GetColor();
		Config::SPE_Amplitude = r_amp;
		Config::SPE_Unit = r_unit;
		Config::SPE_FREDisplay = r_fd;
		Config::SPE_Scale = r_ffs;
		Config::SPE_IsLog = b_islog;
		

        EndDialog(wID);
        return 0;
    }

	BEGIN_DDX_MAP(CSpectrumDlg)
        DDX_RADIO(IDC_SPE_RADIO1, r_amp)
		DDX_RADIO(IDC_SPE_RADIO3, r_unit)
		DDX_RADIO(IDC_SPE_RADIO5, r_ffs)
		DDX_RADIO(IDC_SPE_RADIO8, r_fd)
		DDX_CHECK(IDC_CHECKLP, b_islog)
		//DDX_CONTROL(IDC_COMBOCOLOR, cb_color);
    END_DDX_MAP()

protected:
	int r_amp;
	int r_unit;
	//int r_sd;
	int r_ffs;
	int r_fd;
	bool b_islog;
	//CComboBox cb_color;
	CColorButton cb_bgcolor;

private:
	void UpdateUI(){
		if(r_amp == 1)
			GetDlgItem(IDC_CHECKLP).EnableWindow(TRUE);
		else
			GetDlgItem(IDC_CHECKLP).EnableWindow(FALSE);
	}

public:
	LRESULT OnBnClickedRadio2(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){
		DoDataExchange(TRUE);
		UpdateUI();
		return 1;
	}
};
#endif